// SettingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SettingDlg.h"
#include "afxdialogex.h"
#include "util.h"
#include "ChatMessage.h"
// SettingDlg dialog

IMPLEMENT_DYNAMIC(SettingDlg, CDialogEx)

SettingDlg::SettingDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(SettingDlg::IDD, pParent)
	, m_lport(0)
	, m_rport(0)
	, m_id(0)
	, m_rip(_T(""))
	, m_pass(_T(""))
	, m_config(_T(""))
	, m_lip(_T(""))
	, m_username(_T(""))
{

}

SettingDlg::~SettingDlg()
{
}

void SettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_LPORT, m_lport);
	DDV_MinMaxUInt(pDX, m_lport, 0, 65535);
	DDX_Text(pDX, IDC_EDIT_RPORT, m_rport);
	DDV_MinMaxUInt(pDX, m_rport, 0, 65535);
	DDX_Text(pDX, IDC_EDIT_USER, m_id);
	DDX_Text(pDX, IDC_EDIT_RIP, m_rip);
	DDX_Text(pDX, IDC_EDIT_PASS, m_pass);
	DDV_MaxChars(pDX, m_pass, PASSWORD_LEN);
	DDX_Text(pDX, IDC_EDIT_CONFIG, m_config);
	DDV_MaxChars(pDX, m_config, ENCRYPTION_LEN);
	DDX_Control(pDX, IDC_COMBO_LISTIP, m_cbiplist);
	DDV_MaxChars(pDX, m_rip, 16);
	DDV_MinMaxUInt(pDX, m_id, 0, 4000000000);
	DDX_Text(pDX, IDC_EDIT_NAME, m_username);
	DDV_MaxChars(pDX, m_username, USERNAME_LEN);
}


BEGIN_MESSAGE_MAP(SettingDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &SettingDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// SettingDlg message handlers


BOOL SettingDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  Add extra initialization here
	for_glory::list<for_glory::message> iplist;
	GetIPList(iplist);
	for_glory::list<for_glory::message>::iterator iter;
	char str[128];
	unsigned int i;
	int selected = -1;
	for(iter = iplist.begin();iter < iplist.end();++iter)
	{
		i = iter->length();
		str[i] = '\0';
		while(i--)
			str[i] = (*iter)[i];
		m_cbiplist.AddString(str);
		if(m_lip == str)
			selected = iter.ID;
	}
	m_cbiplist.AddString("All");
    if(selected != -1)
	{
	    m_cbiplist.SetCurSel(selected);
	}
	else
	{
		m_cbiplist.SetCurSel(iplist.size());
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


void SettingDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	int idx = m_cbiplist.GetCurSel();
	m_cbiplist.GetLBText(idx, m_lip);
		
	CDialogEx::OnOK();
}